<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="/WEB-INF/templates/common/taglib.jsp"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>${title }</title>
<link rel="stylesheet"
	href="${basePath}/static/bootstrap/css/bootstrap.css" />
<link href="${basePath}/static/css/basic.css" rel="stylesheet"
	type="text/css">
<link href="${basePath}/static/css/login.css" rel="stylesheet"
	type="text/css">
<link href="${basePath}/static/css/list.css" rel="stylesheet"
	type="text/css">
<script type="text/javascript" src="${basePath}/static/js/jquery.min.js"></script>
<script type="text/javascript"
	src="${basePath}/static/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript"
	src="${basePath}/static/page/jqPaginator/jqPaginator.js"></script>
<script type="text/javascript" src="${basePath}/static/layer/layer.js"></script>
<link href="${basePath}/static/layer/layer_defined.css" rel="stylesheet"
	type="text/css">
<style>
.check_cl {
	width: 15px;
}
</style>
</head>
<body>
	<!--头部-->
	<%@include file="/WEB-INF/templates/common/header.jsp"%>
	<!------导航条-->
	<%@include file="/WEB-INF/templates/common/navigation.jsp"%>

	<!--内容部分-->
	<div class="list_main lay_out" class="clearfix">
		<div class="list_DH">
			<%@include file="/WEB-INF/templates/common/medical_manage.jsp"%>
		</div>
		<div class="list_NR">
			<div class="loc">
				<h3 style="margin: 0">病案返修</h3>
			</div>
			<div class="list_con_table">
				<div class="search_table">
					<ul class="clearfix" style="margin-bottom: 0;">
						<li class="Label_1" style="width:12%">ID号：&nbsp;</li>
						<li class="Label_2"><input class="input_box" type="text"
							name='mrId' id='mrId' value='' /></li>
						<li class="Label_1" style="width:12%">住院次数：&nbsp;</li>
						<li class="Label_2"><input class="input_box" type="text"
							 id='visitNumber' value='' /></li>
						<li class="Label_1" style="width:12%">身份证：&nbsp;</li>
						<li class="Label_2" style="width:24%"><input class="input_box" type="text" 
							name='idCard' id='idCard' value='' /></li>
						<li class="Label_1" style="width:12%">姓名：&nbsp;</li>
						<li class="Label_2"><input class="input_box" type="text" value='' id="name">
					    <li class="Label_1" style="width: 12%">出院科室：&nbsp;</li>
						<li class="Label_2">
							<select class="input_box" id="outHospitalOfficeId">
								<option value="">请选择</option>
								<c:forEach var="office" items="${officeList }">
									
										<option value="${office.code }">${office.name}</option>
								</c:forEach>

						</select>
						</li>
						<li class="Label_1" style="width:12%">出院日期：&nbsp;</li>
						<li class="Label_4" style="width:24%;text-align:center;"><input
							class="input_box" type="text" style="width:42%"
							name='startTime' id='startTime'  value="" 
							onFocus="WdatePicker()" /><span>&nbsp;-&nbsp;</span><input
							class="input_box" type="text" style="width:42%"
							name='endTime' id='endTime'  value="" 
							onFocus="WdatePicker()" />
						</li>	
						<li class="Label_5"><a onclick="queryQua(1,10)">查询</a> <!--  <a href="javascript:exportMainAuditToExcel()">导出</a> -->
						</li>
					</ul>
				</div>
				<table class="Search_tableList" cellpadding="0" cellspacing="0">
					<tr>
						<td class="tdLabel_4">姓名</td>
						<td class="tdLabel_4">ID号</td>
						<td class="tdLabel_4">住院次数</td>
						<td class="tdLabel_4">身份证号</td>
						<td class="tdLabel_4">缺陷</td>

						<td class="tdLabel_4">质控时间</td>
                        <td class="tdLabel_4">操作</td>
					</tr>
					<tr id="loading" style="height:50px;display:none">
	                 <td colspan="7" align="center" ><img src="${basePath}/static/layer/skin/default/loading-2.gif"></td>
	                </tr>
					<tbody id="tbody">
						<!-- <tr>
							<td class="tdLabel_5" rowspan="3"><input type="checkbox"
								class="check_cl"></td>
							<td class="tdLabel_5" rowspan="3">20150611011</td>
							<td class="tdLabel_5" rowspan="3">刘东亮</td>
							<td class="tdLabel_5">2017-08-23</td>
							<td class="tdLabel_5">医嘱</td>

						</tr>
						<tr>
							<td class="tdLabel_5">2017-08-23</td>
							<td class="tdLabel_5">医嘱</td>

						</tr>
						<tr>
							<td class="tdLabel_5">2017-08-23</td>
							<td class="tdLabel_5">医嘱</td>

						</tr> -->
					</tbody>
				</table>
			</div>
			<div class="pageList">
				<ul class="pagination clearfix" id="page_plus"></ul>
				<div class="pagination">
					<div>
						总共：<b id="totalPage">0</b> 条信息 当前页是第 <b id="currentPage">0/0</b> 页
					</div>
				</div>
			</div>
		</div>
	</div>
	</div>
	<!------页脚部分--------->
	<%@include file="/WEB-INF/templates/common/footer.jsp"%>


	<script>
	
	$(function(){
		$("#mrId").focus();
	});
	
	$("#mrId").change(function(){
		var $this=$(this);
		var inentity=$this.val();
		if(inentity!=null && inentity!='' && inentity!=undefined){
			if(isContainMark(inentity)){
				var mrId=inentity.split("-")[0];
				var visitNumber=inentity.split("-")[1];
				
				if(!isNumber(visitNumber)){
					alert("请重新扫描条形码");
					$("#mrId").val("").focus();
					$("#visitNumber").val("");
					
					return;
				}
				//alert(mrId+"--"+visitNumber);
				$("#mrId").val("").val(mrId);
				$("#visitNumber").val("").val(visitNumber);
				queryQua(1, 10);
			}
		}
	});

	function isNumber(value) {
	    var patrn = /^[0-9]*$/;
	    if (patrn.exec(value) == null || value == "") {
	        return false
	    } else {
	        return true
	    }
	}


	function isContainMark(inentity){
		var reg = RegExp(/-/);
		return reg.test(inentity);
	}
	
	
		function queryQua(pageNo, pageSize) {
			
			
			var startTime = $("#startTime").val();
			var endTime = $("#endTime").val();
			var name = $("#name").val();
			var mrId = $("#mrId").val();
			var idCard = $("#idCard").val();
			var outHospitalOfficeId=$("#outHospitalOfficeId").val();
			var onlyId=$("#onlyId").val();
			
			//alert(startTime+"--"+endTime+"--"+name+"--"+mrId+"--"+idCard+"--"+outHospitalOfficeId+"=-"+onlyId);
			
			//return;
			if ((startTime == null || startTime == "")
					&& (endTime == null || endTime == '')
					&& (name == null || name == '')
					&& (mrId == null || mrId == '')
					&& (onlyId == null || onlyId == '')
					&& (outHospitalOfficeId == null || outHospitalOfficeId == '')
					&& (idCard == null || idCard == '')) {
				layer.alert("请输入查询条件!", {
					icon : 0
				});

				return;
			}
			
			$.ajax({
						type : "post",
						data : {
							outHospitalStartTime : startTime,
							outHospitalEndTime : endTime,
							name : name,
							mrId : mrId,
							idNumber : idCard,
							onlyId : onlyId,
							outHospitalCode : outHospitalOfficeId,
							pageNo : pageNo,
							pageSize : pageSize
						},
						url : "${basePath}/audit/autoAudit",
						beforeSend:function(){
			    	 		$("#tbody").html("");
			    	 		$("#loading").show();
			    	 	},
						success : function(data) {
							$("#loading").hide();
							if (data.success) {
								var modifyMapList = data.data.modifyMapList;
								var totalCount = data.data.totalCount;
								var html = "";
								if (modifyMapList.length > 0) {

									page(pageNo, totalCount,pageSize);
									for (var i = 0; i < modifyMapList.length; i++) {
										var modifyMap = modifyMapList[i];
										var medicalErrorLength = modifyMap.medicalErrorLength;
										var medicalErrorList = modifyMap.medicalErrorList;
										for (var j = 0; j < medicalErrorList.length; j++) {
											var  medicalError =medicalErrorList[j];
												if(j==0){
													html+="<tr data-guid="+modifyMap.firstGuid+">"+
													  "	<td class='tdLabel_5' rowspan='"+medicalErrorLength+"'>"+modifyMap.name+"</td>"+
													  "	<td class='tdLabel_5' rowspan='"+medicalErrorLength+"'>"+modifyMap.mrId+"</td>"+
													  "	<td class='tdLabel_5' rowspan='"+medicalErrorLength+"'>"+(modifyMap.visitNumber==undefined?'':modifyMap.visitNumber)+"</td>"+
													  " <td class='tdLabel_5' rowspan='"+medicalErrorLength+"'>"+(modifyMap.idNumber==undefined?'':modifyMap.idNumber)+"</td>"+
													  "	<td class='tdLabel_5'>"+medicalError.name+"</td>"+
													  " <td class='tdLabel_5'>"+medicalError.createTime+"</td>"+
													  " <td class='tdLabel_5' rowspan='"+medicalErrorList.length+"'><a class='btn_qx' style='padding:0px 5px 3px;margin-left:0;' onclick='scan(this)'>修改</a></td>"+
												 	  "</tr>";
												}else{
													html+="<tr>"+
													  "	<td class='tdLabel_5'>"+medicalError.name+"</td>"+
													  " <td class='tdLabel_5'>"+medicalError.createTime+"</td>"+
													 // " <td class='tdLabel_5'><a class='btn_qx' style='padding:0px 5px 3px' onclick='scan(this)'>查看</a></td>"+
													  "</tr>";	
												}
													
												
												
											
												
										}
									}
									$("#tbody").html(html);
								}else{
									$("#tbody").html("");
								}

							}
						}
					})
		}

		 function page(currentPage,totalCounts,pageSize){
			   /*  var pageSize=1; */
	            var visiblePages = 10;
		        var totalPages = Math.ceil(totalCounts/pageSize);
		        $('#page_plus').jqPaginator({
	                totalCounts: totalCounts,
		            pageSize:pageSize,
		            visiblePages: visiblePages,
		            currentPage: currentPage,

		            first:'<li class="first"><a href="javascript:void(0);">首页</a></li>',
		            prev: '<li class="prev"><a href="javascript:void(0);">上一页</a></li>',
		            next: '<li class="next"><a href="javascript:void(0);">下一页</a></li>',
		            last: '<li class="last"><a href="javascript:void(0);">末页</a></li>',
		            page: '<li class="page"><a href="javascript:void(0);">{{page}}</a></li>',
		            onPageChange: function (num,type) {
		          
		            	 if(type !='init'){
		            		 queryQua(num,pageSize);
		                 }
		            	
		                $("#totalPage").html(totalCounts);
		                $("#currentPage").html(num+"/"+totalPages);
		            }
		        });

		    }
 
      //查看事件
      function scan(obj){
		 var target=$(obj);
		 var guid=target.closest("tr").attr("data-guid");
		 window.open('${corePath}/medical_record/edit_home_page_index_form?visitGuid='+guid);
		// window.open('${corePath}/medical_record/searchHomePageIndexForm?visitGuid='+guid);
	 }


	</script>
</body>
</html>